﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.Admin;
using Shop.Model.Dto.Admin.System;
using Shop.Model.View.System;

namespace Shop.AdminApi.Controllers;


/// <summary>
/// 系统常量管理
/// </summary>
[ApiController]
[Route("admin/[controller]")]
public class SysConstantController: ShopControllerBase
{
    private readonly ISysConstantService _constantService;
    private readonly IUserContext _userContext;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="constantService"></param>
    /// <param name="userContext"></param>
    public SysConstantController(ISysConstantService constantService,IUserContext userContext)
    {
        _constantService = constantService;
        _userContext = userContext;
    }

    /// <summary>
    /// 系统配置查询
    /// </summary>
    /// <returns></returns>
    [HttpGet("ConstantList")]
    public AppResult<List<ConstantListVo>> ConstantList()
        => _constantService.ConstantList();
    
    /// <summary>
    /// 修改系统常量
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("UpdateConstant")]
    public AppResult UpdateConstant(UpdateConstantDto dto)
        => _constantService.UpdateConstant(dto, _userContext.Id);
}